package cn.mill.core;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

import cn.mill.common.Context;
import cn.mill.common.Listener;
import cn.mill.common.Node;
import cn.mill.common.data.Item;

public class DefaultContext implements Context {
	
	private String mapping;
	private String tip;
	private Method method;
	private Node node;
	private Object[] parameters;
	private Class<?>[] parameterTypes;
	private Annotation[][] parameterAnnotations;
	private Annotation[] methodAnnotations;
	private Type returnType;
	private Map<String, Item> attachments;
	private Listener listener;
	
	@Override
	public String getMapping() {
		return this.mapping;
	}
	
	@Override
	public String getTip() {
		return tip;
	}
	
	public void setTip(String tip) {
		this.tip = tip;
	}
	
	@Override
	public void setNode(Node node) {
		this.node = node;
	}
	
	@Override
	public Node getNode() {
		return this.node;
	}
	
	@Override
	public Object[] getParameters() {
		return this.parameters;
	}
	
	@Override
	public Class<?>[] getParameterTypes() {
		return this.parameterTypes;
	}
	
	@Override
	public Annotation[][] getParameterAnnotations() {
		return this.parameterAnnotations;
	}
	
	@Override
	public Annotation[] getMethodAnnotations() {
		return this.methodAnnotations;
	}
	
	@Override
	public Map<String, Item> getAttachments() {
		return this.attachments == null ? new HashMap<String, Item>(0) : this.attachments;
	}
	
	@Override
	public Type getReturnType() {
		return this.returnType;
	}
	
	@Override
	public Listener getListener() {
		return this.listener;
	}
	
	@Override
	public void setListener(Listener listener) {
		this.listener = listener;
	}
	
	public void setMapping(String mapping) {
		this.mapping = mapping;
	}
	
	public void setParameters(Object[] parameters) {
		this.parameters = parameters;
	}
	
	public void setParameterTypes(Class<?>[] parameterTypes) {
		this.parameterTypes = parameterTypes;
	}
	
	public void setParameterAnnotations(Annotation[][] parameterAnnotations) {
		this.parameterAnnotations = parameterAnnotations;
	}
	
	public void setMethodAnnotations(Annotation[] methodAnnotations) {
		this.methodAnnotations = methodAnnotations;
	}
	
	public void setReturnType(Type returnType) {
		this.returnType = returnType;
	}
	
	@Override
	public void addAttachments(String key, Item value) {
		if (this.attachments == null) {
			this.attachments = new HashMap<String, Item>();
		}
		this.attachments.put(key, value);
	}
	
	@Override
	public Method getMethod() {
		return this.method;
	}
	
	public void setMethod(Method method) {
		this.method = method;
	}
	
}
